﻿// <copyright file="Vector3DCollection.cs" company="Axelerate Solutions S.A.">
// Copyright (c) Axelerate Solutions S.A.  All rights reserved.
// </copyright>

namespace Axelerate.Silverlight3D.Media.Media3D
{
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.ComponentModel;
    using System.Collections.Generic;
    using System.Collections;
    using System.Collections.ObjectModel;
    using Axelerate.Silverlight3D.Controls;

    /// <summary>
    /// File name: Vector3DCollection.cs
    /// Company: Axelerate Solutions S.A.
    /// Created By: Daniel Rojas
    /// Created Date: 10/06/2008 17:36:30 h.
    /// Description: Represents an ordered collection of Vector3D objects.
    ///   <Modifications>
    ///   </Modifications>
    /// </summary>
    [TypeConverterAttribute(typeof(Vector3DCollectionConverter))]
    public sealed class Vector3DCollection : ObservableCollection<Vector3D>,
    IFormattable
    {

        #region Methods
        
        /// <summary>
        /// Converts a string representation of a collection of Vector3D objects into an equivalent Vector3DCollection
        /// </summary>
        /// <param name="source">The string representation of the collection of Vector3D objects.</param>
        /// <returns>The equivalent Vector3DCollection.</returns>
        public static Vector3DCollection Parse(string source)
        {
            if (source != "")
            {
                string[] vectorStrings = source.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                Vector3DCollection col = new Vector3DCollection();
                foreach (string vectord in vectorStrings)
                {
                    col.Add(Vector3D.Parse(vectord));
                }
                return col;
            }
            return null;
        }
        
        /// <summary>
        /// Creates a string representation of this Vector3DCollection.
        /// </summary>
        /// <returns>String representation of the object.</returns>
        public override string ToString()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder(64);
            foreach (Vector3D item in this)
            {
                if (sb.Length > 0)
                {
                    sb.Append(' ');
                }
                sb.Append(item.ToString());
            }
            return sb.ToString();
        }

        /// <summary>
        /// Creates a string representation of this Vector3DCollection.
        /// </summary>
        /// <param name="provider">Culture-specific formatting information.</param>
        /// <returns>String representation of the object.</returns>
        public string ToString(IFormatProvider provider)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder(64);
            foreach (Vector3D item in this)
            {
                if (sb.Length > 0)
                {
                    sb.Append(' '.ToString(provider));
                }
                sb.Append(item.ToString(provider));
            }
            return sb.ToString();
        }

        #endregion

        #region IFormattable Members

        public string ToString(string format, IFormatProvider formatProvider)
        {
            return this.ToString(formatProvider);
        }

        #endregion
    }
}
